#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int mod=1e9+7,inf=0x3f3f3f3f3f3f3f3f;
const int N=1e3+10,M=2e5+10;
int n,K; 
int pw2[N];
string s,A,B;
int f[N][N][2],g[N][N][2];
int solve(string &Lim)
{
	if(Lim[0]=='0')return 0;
//	cerr << Lim << endl;
	memset(f,0,sizeof(f)),memset(g,0,sizeof(g));
	f[1][0][0]=pw2[n-1];g[1][0][0]=1;
	for ( auto &ch:s )if(ch=='L')ch='R';else if(ch=='R')ch='L';
	for ( int i = 1 ; i < n ; i++ )
	{
		for ( int j = 0 ; j <= K ; j++ )
		{
			f[i][j][0]%=mod,f[i][j][1]%=mod;
			g[i][j][0]%=mod,g[i][j][1]%=mod;
//			cerr << f[i][j][0] << " ";
			f[i+1][j][1]+=f[i][j][1]+pw2[n-i-1]*((j&1)?s[i]=='L':s[i]=='R')*g[i][j][1]%mod;
			g[i+1][j][1]+=g[i][j][1];
			f[i+1][j+1][1]+=f[i][j][1]+pw2[n-i-1]*((j&1)?s[i]=='R':s[i]=='L')*g[i][j][1]%mod;
			g[i+1][j+1][1]+=g[i][j][1];
			if(Lim[i]=='0')
			{
				if(((j&1)&&s[i]=='L')||(j%2==0&&s[i]=='R'))
					f[i+1][j+1][0]+=f[i][j][0],g[i+1][j+1][0]+=g[i][j][0];
				else f[i+1][j][0]+=f[i][j][0],g[i+1][j][0]+=g[i][j][0];
			}else{
				if(((j&1)&&s[i]=='L')||(j%2==0&&s[i]=='R'))
					f[i+1][j+1][1]+=f[i][j][0],g[i+1][j+1][1]+=g[i][j][0],
					f[i+1][j][0]+=f[i][j][0]+pw2[n-i-1]*g[i][j][0]%mod,g[i+1][j][0]+=g[i][j][0];
				else f[i+1][j][1]+=f[i][j][0],g[i+1][j][1]+=g[i][j][0],
					 f[i+1][j+1][0]+=f[i][j][0]+pw2[n-i-1]*g[i][j][0]%mod,g[i+1][j+1][0]+=g[i][j][0];
			}
		}
//		cerr << endl;
	}
	int ans=(f[n][K][0]+f[n][K][1])%mod;
	
	
	memset(f,0,sizeof(f)),memset(g,0,sizeof(g));
	f[1][0][0]=pw2[n-1];g[1][0][0]=1;
	for ( auto &ch:s )if(ch=='L')ch='R';else if(ch=='R')ch='L';
//	cerr << s << endl;
	for ( int i = 1 ; i < n ; i++ )
	{
		for ( int j = 0 ; j <= K ; j++ )
		{
			f[i][j][0]%=mod,f[i][j][1]%=mod;
//			cerr << f[i][j][0] << " ";
			g[i][j][0]%=mod,g[i][j][1]%=mod;
			f[i+1][j][1]+=f[i][j][1]+pw2[n-i-1]*((j&1)?s[i]=='L':s[i]=='R')*g[i][j][1]%mod;
			g[i+1][j][1]+=g[i][j][1];
			f[i+1][j+1][1]+=f[i][j][1]+pw2[n-i-1]*((j&1)?s[i]=='R':s[i]=='L')*g[i][j][1]%mod;
			g[i+1][j+1][1]+=g[i][j][1];
			if(Lim[i]=='0')
			{
				if(((j&1)&&s[i]=='L')||(j%2==0&&s[i]=='R'))
//					cerr << "debug " << i << " " << j << endl,
					f[i+1][j+1][0]+=f[i][j][0],g[i+1][j+1][0]+=g[i][j][0];
				else f[i+1][j][0]+=f[i][j][0],g[i+1][j][0]+=g[i][j][0];
			}else{
				if(((j&1)&&s[i]=='L')||(j%2==0&&s[i]=='R'))
					f[i+1][j+1][1]+=f[i][j][0],g[i+1][j+1][1]+=g[i][j][0],
					f[i+1][j][0]+=f[i][j][0]+pw2[n-i-1]*g[i][j][0]%mod,g[i+1][j][0]+=g[i][j][0];
				else f[i+1][j][1]+=f[i][j][0],g[i+1][j][1]+=g[i][j][0],
					 f[i+1][j+1][0]+=f[i][j][0]+pw2[n-i-1]*g[i][j][0]%mod,g[i+1][j+1][0]+=g[i][j][0];
			}
		}
//		cerr << endl;
	}
	return (ans+f[n][K][0]+f[n][K][1])%mod;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("lost.in","r",stdin);
	freopen("lost.out","w",stdout);
	cin >> n >> K >> s >> A >> B;
	pw2[0]=1;
	for ( int i = 1 ; i <= n ; i++ )pw2[i]=pw2[i-1]*2%mod;
	s=" "+s;
//	int flg=1;
	int ans=solve(B),flg=1; 
	for ( int i = n-1 ; i >= 1 ; i-- )
	{
		if(!flg)break;
		if(A[i]=='0')A[i]='1';
		else A[i]='0',flg=0;
	}
//	cerr << solve(A) << endl;
//	cerr << ans << endl;
	cout << (ans-solve(A)+mod)%mod << endl;
	return 0;
}


